#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;

class Solution{
    public:
    //越位
    vector<int> ans1(vector<int>& digits){
        int len = digits.size();
        int num = 0;
        for(int i = 0; i != len; i++){
            num = num * 10 + digits[i];
        }
        num = num + 1;
        vector<int> ret;
        while(num > 0){
            int temp = num % 10;
            num = num / 10;
            ret.push_back(temp);
        }
        reverse(ret.begin(), ret.end());
        return ret;
    }

    vector<int> ans2(vector<int>& digits){
        int len = digits.size();
        vector<int> up(len+1, 0);
        up[len] = 1;
        for(int i = len-1; i >= 0; i--){
            if(up[i+1] + digits[i] == 10){
                up[i] = 1;
                up[i+1] = 0;
            }else{
                up[i+1] = up[i+1] + digits[i];
            }
        }
        if(up[0] == 0){
            up.erase(up.begin(), up.begin()+1);
        }
        return up;
    }
};

void show(vector<int>& nums){
    int len = nums.size();
    for(int i = 0; i != len-1; i++){
        cout << nums[i] << " " << ends;
    }
    cout << nums[len-1] << endl;
}

void test1(){
    Solution s;
    vector<int> digits = {4,3,2,1};

    vector<int> ret = s.ans2(digits);
    show(ret);
}

void test2(){
    Solution s;
    vector<int> digits = {9,9};

    vector<int> ret = s.ans2(digits);
    show(ret);
}

void test3(){
    Solution s;
    vector<int> digits = {9,8,7,6,5,4,3,2,1,0};

    vector<int> ret = s.ans2(digits);
    show(ret);
}

int main(void){
    test1();
    test2();
    test3();

    return 0;
}